//
//  HeadView.m
//  gdemm
//
//  Created by yongwu on 15/12/1.
//  Copyright © 2015年 goldensoft. All rights reserved.
//

#import "HeadView.h"
@interface HeadView()
@property(nonatomic) CGFloat mWidth;
@end
@implementation HeadView
- (instancetype)init
{
    self = [super init];
    if (self != nil) {
        self.backgroundColor = [Utils UIColorFromHex:GDBLUE];
        _mWidth = [UIScreen mainScreen].bounds.size.width;
        self.frame = CGRectMake(0, 0, _mWidth, HEADHEIGHT);
        [self mBtnLeft];
        [self mTitle];
        [self mBtnRight];
    }
    return self;
}
-(UIButton*)mBtnLeft{
    if (!_mBtnLeft) {
        _mBtnLeft= [[UIButton alloc]init];
        CGFloat btnX = PADDING;
        CGFloat btnY = 3*PADDING;
        if ([DeviceTypeJudge isPadDeviceType]) {
             _mBtnLeft.frame = CGRectMake(btnX, btnY, 20, 20);
        }else{
             _mBtnLeft.frame = CGRectMake(btnX, btnY, 16, 16);
        }
       
        _mBtnLeft.contentMode = UIViewContentModeScaleAspectFit;

        [self addSubview:_mBtnLeft];
    }
    return _mBtnLeft;
}
-(UILabel*)mTitle{
    if (!_mTitle) {
        _mTitle= [[UILabel alloc]init];
        CGFloat originX = CGRectGetMaxX(_mBtnLeft.frame)+PADDING;
        CGFloat originY =2*PADDING;
        CGFloat width = _mWidth - 2*originX;
        CGFloat height = HEADHEIGHT - originY - PADDING;//40;
        _mTitle.textColor = [UIColor whiteColor];
        _mTitle.textAlignment = NSTextAlignmentCenter;
        _mTitle.frame = CGRectMake(originX, originY, width, height);
        _mTitle.font = [UIFont boldSystemFontOfSize:14];
        
        [self addSubview:_mTitle];
        
    }
    return _mTitle;
}

-(UIButton*)mBtnRight{
    if (!_mBtnRight) {
        _mBtnRight= [[UIButton alloc]init];
        CGFloat orginX = CGRectGetMaxX(_mTitle.frame)+PADDING;
        CGFloat originY = _mBtnLeft.frame.origin.y;
        CGFloat width = 2.5*PADDING;
        CGFloat height = _mBtnLeft.frame.size.height;
        [self showRightBtn:NO];
        _mBtnRight.frame = CGRectMake(orginX, originY, width, height);
        [self addSubview:_mBtnRight];
        
    }
    return _mBtnRight;
}
+(instancetype)initWithDefaultHeader{
    HeadView *view = [[HeadView alloc]init];
    [view showRightBtn:NO];
    [view.mBtnLeft setBackgroundImage:[UIImage imageNamed:@"nav_left_button"] forState:UIControlStateNormal];
    return view;
}

-(void)showLeftBtn:(BOOL)isHidden{
    self.mBtnLeft.hidden = !isHidden;
}
-(void)showRightBtn:(BOOL)isHidden{
    self.mBtnRight.hidden = !isHidden;
}
-(void)setTitleLable:(NSString *)titleStr{
    self.mTitle.text = titleStr;
}
@end
